﻿namespace CompanyPayRollSystem
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using CompanyPayRollSystem.Database;
    using CompanyPayRollSystem.BusinessLayer;

    /// <summary>
    /// 
    /// </summary>
    public partial class SalaryItemsForm : Form
    {
        /// <summary>
        /// 
        /// </summary>
        private EmployeeSalaryItem employeeSalaryItem;

        /// <summary>
        /// Initializes a new instance of the <see cref="SalaryItemsForm"/> class.
        /// </summary>
        /// <param name="employeeSalaryItem">The salary item.</param>
        public SalaryItemsForm(EmployeeSalaryItem employeeSalaryItem)
        {
            InitializeComponent();
            this.employeeSalaryItem = employeeSalaryItem;
            this.SetSalary();
        }

        /// <summary>
        /// Handles the Click event of the btnMarkAsDelivered control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnMarkAsDelivered_Click(object sender, EventArgs e)
        {
            if (this.employeeSalaryItem.IsDelivered)
            {
                MessageBox.Show("Salary already marked as delivered.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                EmployeeSalaryItemsManager.MarkAsDelivered(this.employeeSalaryItem, DateTime.Now);
                MessageBox.Show("Salary marked as delivered successfully.", "Marked", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Salary not marked as delivered.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        /// <summary>
        /// Sets the salary.
        /// </summary>
        private void SetSalary()
        {
            this.lblEmployeeName.Text = this.employeeSalaryItem.Employee.EmployeeName;
            this.lblBasicSalary.Text = this.employeeSalaryItem.Employee.Salary.ToString();
            this.lblBonus.Text = this.employeeSalaryItem.Bonus.ToString();
            this.lblTotal.Text = EmployeeSalaryItemsManager.CalculateEmployeeSalary(this.employeeSalaryItem).ToString();
            this.lbl_Incentive.Text = this.employeeSalaryItem.Incentive.ToString();
        }
    }
}
